package c03正则表达式;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author yuanwl
 * @date 2019-08-14 20:46
 */
public class P {
    private static final String patternStr = "<subject>(.*?)</subject>";
    private static Pattern pattern = Pattern.compile(patternStr);

    public static void main(String[] args) {
        String[] strs = splitSubjectAndContent("zxcas<subject>【跨境e链】首次登录邀请码</subject>尊敬的客户，");
        System.err.println(strs[0]);
        System.err.println(strs[1]);
    }

    private static String[] splitSubjectAndContent(String htmlText) {
        String[] s = new String[2];

        Matcher matcher = pattern.matcher(htmlText);
        if (matcher.find()) {
            s[0] = matcher.group(1);
        }
        s[1] = htmlText.replaceFirst(patternStr, "");

        return s;
    }
}
